package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.common.resp.UserResp
import com.polaris.live.net.liveService
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.CallLabelRespItem
import com.polaris.live.resp.go_resp.OtherUserIdBean
import com.polaris.live.resp.go_resp.SaveCallLabelBean

/**
 * CallEndViewModel
 *
 * @author Created by 半仙 on 2023/9/18/018 9:21
 */
class CallEndViewModel : BaseViewModel() {

    val mAddFollowerLiveData = MutableLiveData<ResultState<Any>>()
    fun addFollower(otherId: Long) {
        requestLoading({ userService.addFollower(OtherUserIdBean(otherId)) }, mAddFollowerLiveData)
    }

    val mCallLabelLiveData = MutableLiveData<ResultState<List<CallLabelRespItem>>>()
    fun getCallLabel(callId: Long) {
        requestLoading({ liveService.getCallLabel(callId) }, mCallLabelLiveData)
    }

    val mLabelEndLiveData = MutableLiveData<ResultState<Any>>()
    fun saveCallLabel(callId: Long, labels: MutableList<Int>) {
        val saveCallLabelBean = SaveCallLabelBean(
            callId, labels
        )
        requestLoading({ liveService.saveCallLabel(saveCallLabelBean) }, mLabelEndLiveData)
    }

    val mUserLiveData = MutableLiveData<UserResp>()
    fun getUser() {
        request({ userService.getUserData() }, {
            UserManager.setUser(it)
            mUserLiveData.value = it
        })
    }
}